package com.chushouya.controller.order.api;

import com.chushouya.common.constant.ServiceType;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.RepeatSubmit;
import com.chushouya.order.dto.admin.orderclothesproduct.OrderClothesProductQuery;
import com.chushouya.order.dto.api.order.OrderCancelApiDTO;
import com.chushouya.order.dto.api.order.OrderUserApiDTO;
import com.chushouya.order.dto.api.orderclothesproduct.OrderClothesApiDTO;
import com.chushouya.order.dto.api.orderclothesproduct.OrderClothesListApiDTO;
import com.chushouya.order.dto.api.orderclothesproduct.OrderClothesSubmitDTO;
import com.chushouya.order.service.api.OrderClothesApiService;
import com.chushouya.order.service.api.OrderClothesSubmitApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 旧衣订单API控制器
 */
@Api(tags = ServiceType.API + "旧衣订单接口")
@RestController
@RequestMapping(ServiceType.API + "/order/clothes")
@Slf4j
public class OrderClothesApiController {

    @Resource
    private OrderClothesApiService orderClothesApiService;

    @Resource
    private OrderClothesSubmitApiService orderClothesSubmitApiService;

    @ApiOperation("创建旧衣订单")
    @PostMapping("/create")
    @RepeatSubmit
    public Response<OrderUserApiDTO> createOrder(@RequestBody @Validated OrderClothesSubmitDTO submitDTO) {
        log.info("创建旧衣订单请求：{}", submitDTO);
        return Response.success(orderClothesSubmitApiService.createOrder(submitDTO));
    }

    @ApiOperation("获取旧衣订单列表")
    @GetMapping("/list")
    public Response<PageResult<OrderClothesListApiDTO>> getOrderList(OrderClothesProductQuery query) {
        PageResult<OrderClothesListApiDTO> result = orderClothesApiService.getOrderList(query);
        return Response.success(result);
    }

    @ApiOperation("获取旧衣订单详情")
    @GetMapping("/detail")
    public Response<OrderClothesApiDTO> getOrderDetail(@RequestParam String orderNo) {
        log.info("查询旧衣订单详情，订单号：{}", orderNo);
        OrderClothesApiDTO result = orderClothesApiService.getOrderDetail(orderNo);
        return Response.success(result);
    }

    @ApiOperation("取消旧衣订单")
    @PostMapping("/cancel")
    public Response<String> cancelOrder(@RequestBody OrderCancelApiDTO dto) {
        log.info("取消旧衣订单，订单号：{}", dto);
        orderClothesApiService.cancelOrder(dto);
        return Response.success("订单取消成功");
    }
}
